<%--@elvariable id="storeId" type=""--%>
<%--@elvariable id="flag" type=""--%>
<%--@elvariable id="dishName" type=""--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="com.delivery.www.util.PageSupport" %><html>
<head>
    <title>菜品</title>
    <style>
        div {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }

        table, tr, th, td {
            border: 1px solid #5fbdcb;
        }

        table {
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<div>
    <table id="table1"></table>
    <form id="form" action="${pageContext.request.contextPath}/dish.do?method=selectDish" method="post">
        <label>
            <input type="text" name="storeId" value="${param.storeId}" hidden>
        </label>
        <span>店铺名：</span>
        <label for="dishName"></label><input type="text" name="dishName" id="dishName" value="${dishName}">
        <label for="flag"></label><input type="text" id="flag" value="${flag}" hidden>
        <input type="submit" id="button" value="查询"><br>
    </form>
    <table>
        <tr>
            <th>菜品名</th>
            <th>价格</th>
            <th>描述</th>
            <th>照片</th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
        </tr>
        <%--@elvariable id="dishes" type="java.util.List"--%>
        <c:forEach var="dish" items="${dishes}">
            <tr>
                <td>
                        ${dish.dishName}
                </td>
                <td>
                        ${dish.price}
                </td>
                <td>
                        ${dish.describe}
                </td>
                <td>
                    <img src="/photo/${dish.dishId}.jpg" alt="${dish.dishId}照片" width="100px">
                </td>
                <td>
                    <a href="DoOrder.jsp?storeId=${param.storeId}&dishId=${dish.dishId}">下单</a>
                </td>
                <td>
                    <a href="DoCart.jsp?storeId=${param.storeId}&dishId=${dish.dishId}">加入购物车</a>
                </td>
                <td>
                    <a href="DoThumb.jsp?storeId=${param.storeId}&dishId=${dish.dishId}">点赞</a>
                </td>
                <td>
                    <a href="DoCollect.jsp?storeId=${param.storeId}&dishId=${dish.dishId}">收藏</a>
                </td>
            </tr>
        </c:forEach>
    </table>
    <br>
    <a href="${pageContext.request.contextPath}/dish.do?method=selectDish&currentPageNo=1&storeId=${param.storeId}">首页</a>
    <c:if test="${PageSupport.currentPageNo>1}">
        <a href="${pageContext.request.contextPath}/dish.do?method=selectDish&currentPageNo=${PageSupport.currentPageNo-1}&storeId=${param.storeId}">上一页</a>
    </c:if>
    <c:if test="${PageSupport.currentPageNo<PageSupport.totalPageCount}">
        <a href="${pageContext.request.contextPath}/dish.do?method=selectDish&currentPageNo=${PageSupport.currentPageNo+1}&storeId=${param.storeId}">下一页</a>
    </c:if>
    <a href="${pageContext.request.contextPath}/dish.do?method=selectDish&currentPageNo=${PageSupport.totalPageCount}&storeId=${param.storeId}">尾页</a><br>
    <a href="AllStorePage.jsp">返回</a>
</div>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    $(function () {
        $.ajax({
            url: "http://localhost:8080/coupon.do",
            type: "post",
            data: {
                storeId: ${param.storeId},
                method: 'selectCoupon'
            },
            dataType: "text",
            success: function (data) {
                let parse = JSON.parse(data);
                let table1 = document.querySelector('#table1');
                if (parse.length === 0) {
                    let tr = document.createElement('tr');
                    table1.appendChild(tr);
                    let th = document.createElement('th');
                    th.innerText = '该店铺没有优惠券可用';
                    tr.appendChild(th);
                } else {
                    for (let i = 0; i < parse.length; i++) {
                        let tr = document.createElement('tr');
                        table1.appendChild(tr);
                        let th1 = document.createElement('th');
                        tr.appendChild(th1);
                        th1.innerText = '优惠券id';
                        let td1 = document.createElement('td');
                        tr.appendChild(td1);
                        td1.innerText = parse[i].couponId;
                        let th2 = document.createElement('th');
                        tr.appendChild(th2);
                        th2.innerText = '优惠券消费规则';
                        let td2 = document.createElement('td');
                        tr.appendChild(td2);
                        td2.innerText = '满' + parse[i].min + '减' + parse[i].value;
                        let td3 = document.createElement('td');
                        tr.appendChild(td3);
                        let a = document.createElement('a');
                        a.innerText = '领取';
                        a.href = 'ReceiveCoupon.jsp?couponId=' + parse[i].couponId + '&storeId=${param.storeId}' ;
                        td3.appendChild(a);
                    }
                }
            }
        })
        let element = document.querySelector('#flag');
        let element1 = document.querySelector('#button');
        if (element.value === "") {
            element1.click();
        }
    })
</script>
</body>
</html>
